package org.cid54.bukkit.command;

import org.cid54.bukkit.command.util.PlayerCommand;
import org.cid54.bukkit.command.util.Command;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.bukkit.event.player.PlayerChatEvent;
import org.cid54.bukkit.Cid54PlayerListener;

/**
 *
 * @author Cid54
 */
public class HelpCommand implements PlayerCommand {
    
    public String getCommand() {
        return "help";
    }
    
    public String getHelpText() {
        return "Displays all commands";
    }
    
    public boolean execute(String command, PlayerChatEvent event, Cid54PlayerListener listener) {
        
        List<Command> commands = new ArrayList<Command>(listener.getCommands().values());
        
        Collections.sort(commands, new Comparator<Command>() {
            
            public int compare(Command o1, Command o2) {
                return o1.getCommand().compareTo(o2.getCommand());
            }
        });
        
        event.getPlayer().sendMessage("!! : Repeat last succesfull command");
        
        for (Command c : commands) {
            
            event.getPlayer().sendMessage(c.getCommand() + " : " + c.getHelpText());
            
        }
        
        return true;
        
    }
}
